package com.sunny.ynhz.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by puma on 2017/11/16.
 */

public class BeanUtils {
    public static Map<String, String> objectToMap(Object obj){
        if(obj == null){
            return null;
        }

        Map<String, String> map = new HashMap<String, String>();

        Field[] declaredFields = obj.getClass().getDeclaredFields();
        try {
            for (Field field : declaredFields) {
                field.setAccessible(true);
                map.put(field.getName(), field.get(obj)==null?null:field.get(obj).toString());
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return map;
    }
}
